﻿
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Linq.Dynamic;
using System.Text;
using System.Threading.Tasks;
using Abp;
using Abp.Application.Services.Dto;
using Abp.Authorization;
using Abp.AutoMapper;
using Abp.Configuration;
using Abp.Domain.Repositories;
using Abp.Extensions;
using Abp.Linq.Extensions;
using KDS.Mes.Mes.Parts.Dtos;
using KDS.Mes.DataExporting.Excel.EpPlus;
using Abp.Timing.Timezone;
using Abp.Runtime.Session;
using KDS.Mes.Dto;

namespace KDS.Mes.Mes.Parts
{
    /// <summary>
    /// 零件信息的导出EXCEL功能的实现
    /// </summary>
    public class PartListExcelExporter : EpPlusExcelExporterBase, IPartListExcelExporter
    {
     
        private readonly ITimeZoneConverter _timeZoneConverter;
        private readonly IAbpSession _abpSession;


        /// <summary>
        /// 构造方法
        /// </summary>
        public PartListExcelExporter(ITimeZoneConverter timeZoneConverter,     IAbpSession abpSession)
        {
                       _timeZoneConverter = timeZoneConverter;    
                     _abpSession = abpSession;
        }

    

         /// <summary>
        /// 导出零件信息到EXCEL文件
        /// <param name="partListDtos">导出信息的DTO</param>
        /// </summary>
    public    FileDto ExportPartToFile(List<PartListDto> partListDtos){


var file=CreateExcelPackage("partList.xlsx",excelPackage=>{

var sheet=excelPackage.Workbook.Worksheets.Add(L("Part"));
                    sheet.OutLineApplyStyle = true;

                    AddHeader(
                        sheet,
                          L("AlcCodeId"),  
     L("SeatPositionId"),  
     L("BackrestAssemblyNo"),  
     L("CushionAssemblyNo"),  
     L("BackrestCoverNo"),  
     L("CushionCoverNo"),  
     L("BackrestFoamNo"),  
     L("CushionFoamNo"),  
     L("BackFrameNo"),  
     L("SABNo"),  
     L("HeadrestNo"),  
     L("CenterHeadrestNo"),  
     L("ArmRestNo"),  
     L("BuckleNo"),
      L("SittingBasinNo"),
     L("BackplaneNo"),  
     L("AdjusterNo"),  
     L("AdjusterPlateNo"),  
     L("CushioSsupportNo"),  
     L("LastModificationTime"),  
     L("CreationTime")  
                        );
         AddObjects(sheet,2,partListDtos,
            
      _ => _.AlcCode,   
       
      _ => _.SeatPositionName,   
       
      _ => _.BackrestAssemblyNo,   
       
      _ => _.CushionAssemblyNo,   
       
      _ => _.BackrestCoverNo,   
       
      _ => _.CushionCoverNo,   
       
      _ => _.BackrestFoamNo,   
       
      _ => _.CushionFoamNo,   
       
      _ => _.BackFrameNo,   
       
      _ => _.SABNo,   
       
      _ => _.HeadrestNo,   
       
      _ => _.CenterHeadrestNo,   
       
      _ => _.ArmRestNo,   
       
      _ => _.BuckleNo,

       _ => _.SittingBasinNo,

      _ => _.BackplaneNo,   
       
      _ => _.AdjusterNo,   
       
      _ => _.AdjusterPlateNo,   
       
      _ => _.CushioSsupportNo,
       _ => _.ThreadColorNo,

 _ =>_timeZoneConverter.Convert( _.LastModificationTime,_abpSession.TenantId, _abpSession.GetUserId()),          
 _ =>_timeZoneConverter.Convert( _.CreationTime,_abpSession.TenantId, _abpSession.GetUserId())   
);
                    //写个时间转换的吧
          //var creationTimeColumn = sheet.Column(10);
                    //creationTimeColumn.Style.Numberformat.Format = "yyyy-mm-dd";

        for (var i = 1; i <= 20; i++)
                    {
                        sheet.Column(i).AutoFit();
                    }       

});
   return file;

}


 

 
  

    }
    }
